unit BD_TestHead;

interface
uses Vcl.StdCtrls, Vcl.Dialogs;

type TTestHead = class
  public
  //Data members
  solFastestState: Boolean;   //Fastest Head solenoid on/off
  solSealState: Boolean;    //blocking (sealing) solenoid state
  solVentState: Boolean;    //vent solenoid state
  solHighLowState: Boolean;   //High Pressure solenoid state
  lmpTIP: Boolean;        //Test In Progress lamp
  lmpSens: Boolean;       //Sensor Contact lamp
  lmpPass: Boolean;       //Pass lamp
  lmpFail: Boolean;       //Fail lamp
  procedure Intialize;      //configure solenoids and I/O for start up
  function SetFastest(val: Boolean):Boolean;   //turn Fastest head on/off
  function SetSeal(val: Boolean):Boolean;   // turn seal on/off
  function SetVent(val: Boolean):Boolean;   // turn vent on/off (true = vent off)
  function SetHighLow(val: Boolean):Boolean;  //toggle High Low (true = high)
  function SetTIP(val: Boolean):Boolean;   // turn TIP Lamp on/off (true = ON)
  function SetSens(val: Boolean):Boolean;   // turn Sensor Contact Lamp on/off (true = ON)
  function SetPass(val: Boolean):Boolean;   // turn Pass Lamp on/off (true = ON)
  function SetFail(val: Boolean):Boolean;   // turn Fail Lamp on/off (true = ON)
end;

implementation

uses BlueDiamondUtilV1, BD_LabJack;

(******************************************************************************
  Initialize():  Initialize the test head I/O, lamps and solenoids to a know state
******************************************************************************)
procedure TTestHead.Intialize;
begin
  SetFastest(False);
  SetSeal(False);
  SetVent(False);
  SetHighLow(False);
  SetTip(False);
  SetTIP(False);
  SetSens(False);
  SetPass(False);
  SetFail(False);
end;

(*****************************************************************************
  SetFastest(): Set the Fast-test head on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetFastest(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PFASTEST,1);
        solFastestState := True;
     end
     else
       begin
        LJ.PutBit(PFASTEST,0);
        solFastestState := False;
       end;
   except
        ShowMessage('Unable to update Fas-test solenoid.');
    end;
    result := solFastestState;
end;
(*****************************************************************************
  SetSeal(): Set the seal solenoid on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetSeal(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PSEAL,1);
        solSealState := True;
     end
     else
       begin
        LJ.PutBit(PSEAL,0);
        solSealState := False;
       end;
   except
        ShowMessage('Unable to update seal solenoid.');
    end;
    result := solSealState;
end;
(*****************************************************************************
  SetVent(): Set the Vent solenoid on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetVent(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PVENT,1);
        solVentState := True;
     end
     else
       begin
        LJ.PutBit(PVENT,0);
        solVentState := False;
       end;
   except
        ShowMessage('Unable to update vent solenoid.');
    end;
    result := solVentState;
end;
(*****************************************************************************
  SetHighLow(): Set the High/Low Solenoid on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetHighLow(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PHIGHLOW,1);
        solHighLowState := True;
     end
     else
       begin
        LJ.PutBit(PHIGHLOW,0);
        solHighLowState := False;
       end;
   except
        ShowMessage('Unable to update High/Low solenoid.');
    end;
    result := solHighLowState;
end;
(*****************************************************************************
  SetTIP): Set the Test In Process lamp on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetTIP(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PTIP,1);
        lmpTIP := True;
     end
     else
       begin
        LJ.PutBit(PTIP,0);
        lmpTIP := False;
       end;
   except
        ShowMessage('Unable to update Test In Progress Lamp.');
    end;
    result := lmpTIP;
end;

(*****************************************************************************
  SetSens): Set the Sensor Contact lamp on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetSens(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PSENS,1);
        lmpSens := True;
     end
     else
       begin
        LJ.PutBit(PSENS,0);
        lmpSens := False;
       end;
   except
        ShowMessage('Unable to update Sensor Contact Lamp.');
    end;
    result := lmpSens;
end;

(*****************************************************************************
  SetPass): Set the Pass lamp on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetPass(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PPASS,1);
        lmpPass := True;
     end
     else
       begin
        LJ.PutBit(PPASS,0);
        lmpPASS := False;
       end;
   except
        ShowMessage('Unable to update PASS Lamp.');
    end;
    result := lmpPass;
end;

(*****************************************************************************
  SetFail): Set the Fail lamp on or off & set logic accordingly.
******************************************************************************)
function TTestHead.SetFail(val: Boolean):Boolean;
begin
  try
    if val then
      begin
        LJ.PutBit(PFAIL,1);
        lmpFail := True;
     end
     else
       begin
        LJ.PutBit(PFAIL,0);
        lmpFail := False;
       end;
   except
        ShowMessage('Unable to update Fail Lamp.');
    end;
    result := lmpFail;
end;
end.
